<?php
/**
 * Created by 荣耀电竞.
 * User: 林子彦 <278805354@qq.com>
 * Date: 2018/6/29 0029
 * Time: 9:59
 */

namespace App\FreeBird\Controllers\Home;

use App\Base\Controllers\Controller;
use App\FreeBird\Contracts\StoreUserInterface;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;


class UserController extends Controller
{
    /**
     * 获取分类
     * @return StoreUserInterface
     */
    public function getStoreUserInterface()
    {
        return app()->make(StoreUserInterface::class);
    }

    /**
     *  获取用户审请
     * @param Request $request
     */
    public function setUserApply(Request $request)
    {
        return $this->getStoreUserInterface()->setUserInfo($request->all());
    }

    public function getUserInfo(Request $request)
    {
        $where = function ($query) {
            $query->where("uid", AUID);
        };
        return $this->getStoreUserInterface()->getUserInfo($where);
    }

    /**
     *  邦定手机号
     * @param Request $request
     */
    public function bindUserMobile(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'mobile' => 'required',
            'code' => 'required',
        ], ["mobile.required" => '手机号是必须的', "code.required" => '验证码是必须的']);
        if ($validator->fails()) {
            $this->throwValidatorException($validator);
        }
        return $this->getStoreUserInterface()->bindUserMobile($request->all());
    }


    /***
     * 更新用户信息
     * @param Request $request
     */
    public function updateUserAddInfo(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'class' => 'required',
            'remark' => 'required',
        ], ["class.required" => '手机号是必须的', "remark.required" => '验证码是必须的']);
        if ($validator->fails()) {
            $this->throwValidatorException($validator);
        }
        return $this->getStoreUserInterface()->updateUserAddInfo($request->all());
    }
    /**
     * 获取用户信息
     * @param Request $request
     */
    public function getUserAddInfo(Request $request){

        return $this->getStoreUserInterface()->wxUserInfo(AUID);
    }




}